home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / cfilesys.zip / FS_DEMO.CPP < prev    next >
C/C++ Source or Header  |  1994-06-19  |  5KB  |  152 lines

  1.  
  2. //***************************************************************************
  3. //
  4. // Program:                FS_DEMO.EXE
  5. //
  6. // Purpose:                To demostrate the use of the CFileSystem class.
  7. //
  8. // Copyright:            Copyright 1993, 1994 Scott P. Leslie, All Rights Reserved.
  9. //
  10. // Version:                Version 1.1 for MS Windows 3.1 and MSVC 1.0.
  11. //
  12. // Important:            Read the README.TXT file included with this distribution
  13. //                                before using this code.
  14. //
  15. // Shareware:            This code is ShareWare.  If you use it, you should register
  16. //                                it with the author.  If you do not register it after 14 days
  17. //                                of use, you must discontinue using it.
  18. //
  19. //                                Contact the author at ScotLeslie@aol.com for more info.
  20. //
  21. // Distribution:    You may distribute this code unmodified as long as all
  22. //                                accompanying documentation and notes are also distributed.
  23. //
  24. // Disclaimer:        This code is provided as is with no implied or express
  25. //                                warranties.  You should test this code for your particular
  26. //                                use on non-critical data before using it in a production
  27. //                                system.
  28. //
  29. //***************************************************************************
  30.  
  31.  
  32. #include "stdio.h"
  33.  
  34. #include "filesys.h"
  35.  
  36.  
  37. void
  38. main()
  39. {
  40.     CFileSystem    fs;
  41.  
  42.     // Get the file system name
  43.  
  44.     CString FileSystemName = fs.GetCurrentFileSystem();
  45.     CString VolLabel = fs.GetVolumeLabel(FileSystemName);
  46.     printf("Volume Label for %s = %s\n", (const char *) FileSystemName, (const char *) VolLabel);
  47.  
  48.     // Get the current directory information
  49.  
  50.     CString CurrentDir = fs.GetCurrentDirectory();
  51.     printf("Current Directory = %s\n", (const char *) CurrentDir);
  52.  
  53.     // Get the number of bytes under the current directory
  54.  
  55.     LONG lDirSize = fs.GetDirectorySize(CurrentDir, "*.*", TRUE);
  56.     printf("Current Directory Size = %ld\n", lDirSize);
  57.  
  58.     // Print out a directory listing.
  59.     CStringList *pDirList = fs.GetDirectory("*.*", CFileSystem::normal, TRUE);
  60.     printf("\nDirectory Listing:\n");
  61.     CFileSystem::Sort(pDirList);
  62.     for (int i = 0; i < pDirList->GetCount(); i++)
  63.     {
  64.         CFileStatus Status;
  65.         CString FileName = pDirList->GetAt(pDirList->FindIndex(i));
  66.  
  67.         if (CFile::GetStatus((const char *) FileName, Status))
  68.         {
  69.             printf("\t%s\t%ld\n", (const char *) FileName, Status.m_size);
  70.         } // if
  71.     } // for
  72.     delete pDirList;
  73.     pDirList = NULL;
  74.  
  75.  
  76.     //**********************************************************************
  77.     // Test Cases
  78.     //**********************************************************************
  79.  
  80.  
  81.     // Test making directories.
  82.     VERIFY(fs.MakeDirectory("foo_test"));
  83.     VERIFY(fs.MakeDirectory("foo_test\\subdir1"));
  84.     VERIFY(fs.MakeDirectory("foo_test\\subdir2"));
  85.  
  86.     // Test making a path (ie. Multiple directories with one call).
  87.     VERIFY(fs.MakePath("foo_test\\subdir3\\lower1"));
  88.     VERIFY(fs.MakePath("foo_test\\subdir3\\lower2"));
  89.     VERIFY(fs.MakePath("foo_test\\subdir3\\lower2") == FALSE);
  90.  
  91.     // Test file copying.
  92.     VERIFY(fs.CopyFile("test1.dat", "foo_test\\test2.dat"));
  93.     VERIFY(fs.CopyFile("test1.dat", "foo_test\\test2.dat") == FALSE);
  94.     VERIFY(fs.CopyFile("test3.dat", "foo_test\\test3.dat") == FALSE);
  95.     VERIFY(fs.CopyFile("test1.dat", "foo_test\\subdir1\\test2.dat"));
  96.     VERIFY(fs.CopyFile("test1.dat", "foo_test\\subdir2\\test2.dat"));
  97.  
  98.     // Test file comparisons.
  99.     VERIFY(fs.CompareFiles("test1.dat", "foo_test\\test2.dat", 20000) == TRUE);
  100.     VERIFY(fs.CompareFiles("test1.dat", "foo_test\\test2.dat") == TRUE);
  101.     VERIFY(fs.DeleteFile("foo_test\\test2.dat") == TRUE);
  102.     VERIFY(fs.CompareFiles("test1.dat", "foo_test\\test2.dat") == FALSE);
  103.     VERIFY(fs.CompareFiles("test3.dat", "foo_test\\test2.dat") == FALSE);
  104.  
  105.     // Test file renaming.
  106.     VERIFY(fs.CopyFile("test1.dat", "foo_test\\test2.dat"));
  107.     VERIFY(fs.RenameFile("foo_test\\test2.dat", "foo_test\\test3.dat") == TRUE);
  108.     VERIFY(fs.CopyFile("test1.dat", "foo_test\\test2.dat"));
  109.     VERIFY(fs.RenameFile("foo_test\\test2.dat", "foo_test\\test3.dat") == FALSE);
  110.     VERIFY(fs.RenameFile("foo_test\\test4.dat", "foo_test\\test5.dat") == FALSE);
  111.  
  112.     // Test directory deletion.
  113.     VERIFY(fs.DeleteDirectory("foo_test", TRUE) == TRUE);
  114.     VERIFY(fs.DeleteDirectory("foo_test", TRUE) == FALSE);
  115.     VERIFY(fs.DeleteDirectory("foo_test2", TRUE) == FALSE);
  116.     VERIFY(fs.DeleteDirectory("foo_test2", FALSE) == FALSE);
  117.  
  118.     // Test Path Parsing.
  119.     VERIFY(fs.GetPath("c:\\foo\\bar\\what.txt") == "c:\\foo\\bar\\");
  120.     VERIFY(fs.GetPath("c:\\foo\\bar\\") == "c:\\foo\\bar\\");
  121.     VERIFY(fs.GetPath("c:\\foo\\bar") == "c:\\foo\\");
  122.  
  123.     // Test FileName Parsing.
  124.     VERIFY(fs.GetFileName("c:\\foo\\bar\\what.txt") == "what.txt");
  125.     VERIFY(fs.GetFileName("what.txt") == "what.txt");
  126.     VERIFY(fs.GetFileName("c:\\foo\\bar\\") == "");
  127.  
  128.     // Test FileSystem Volume information.
  129.     CStringList *pFSList = fs.GetFileSystemList();
  130.     for (POSITION pos = pFSList->GetHeadPosition(); pos != NULL; )
  131.     {
  132.         CString FSName = pFSList->GetNext(pos);
  133.  
  134.         CString VolLabel = fs.GetVolumeLabel(FSName);
  135.         if (VolLabel != "")
  136.         {
  137.             printf("Volume Label for %s = %s\n", (const char *) FSName, (const char *) VolLabel);
  138.         } // if
  139.         else
  140.         {
  141.             printf("Volume Label for %s = << Not Available >>\n", (const char *) FSName);
  142.         } // else
  143.  
  144.         printf("FileSystem Type = %ld\n", fs.GetFileSystemType(FSName));
  145.  
  146.     } // for
  147.     delete pFSList;
  148.     pFSList = NULL;
  149.  
  150. } // main 
  151.  
  152.